<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <com :g="gift"></com>
    </div>
</body>

</html>
<template id="com">
    <fieldset>
        <legend>一个组件</legend>
        <h1>g:{{g}}</h1>
    </fieldset>
</template>
<script src='https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js'></script>
<script>
    Vue.component('com', {
        template: "#com",
        // props:['g']
        // 校验props
        props: {
            //推荐这么写,一定程度确保类型是安全的
            g: {
                //类型
                type: Number,
                //是否必传
                required: true,
                //默认值
                default() {
                    return '默认值'
                }
            }
        }
    })

    let vm = new Vue({
        el: "#app",
        data: {
            gift: '12312'
        }
    })
</script>